﻿/*****************************************************************
 * Copyright (C) Newegg Corporation. All rights reserved.
 * 
 * Author       :  Bill Li (Bill.S.Li@newegg.com)
 * Create Date  :  
 * Usage        :  
 *
 * RevisionHistory
 * Date         Author               Description
 * 
*****************************************************************/
using System.Text;

namespace TemplateEngine.TranslateCommand
{
    internal class IfTranslate : ITranslate
    {
        public string Translate(TemplateNode node, System.Xml.XmlNode xmlNode)
        {
            var when = node.Attributes["test"];
            if (NodeTranslateUtil.ExecuteIf(when, xmlNode, node))
            {
                StringBuilder html = new StringBuilder();
                html.Append(node.ResultStr);

                foreach (var item in node.Nodes)
                {
                    html = html.Replace("{[" + item.NodeGuid.ToString("N") + "]}", item.TranslateNode(xmlNode));
                }
                return html.ToString();
            }
            else
            {
                return string.Empty;
            }

        }
    }
}
